<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    class Emiter {
        subs = Object.create(null);
        on(name, handler) {
            this.subs[name] = this.subs[name] || [];
            this.subs[name].push(handler)

        }
        emit(name) {
            if (this.subs[name]) {
                this.subs[name].forEach(handler => {
                    handler()
                });
            }
        }
    }
    let obj = new Emiter();
    obj.on('click', () => {
        console.log('xxxx')
    })
    obj.on('click', () => {
        console.log('oooo')
    })
    obj.emit('click')
</script>

</html>